package com.example.project_01.controller;

import com.example.project_01.dto.MedicalPolicyQueryDTO;
import com.example.project_01.model.MedicalPolicyModel;
import com.example.project_01.pojo.MedicalPolicy;
import com.example.project_01.service.MedicalPolicyService;
import com.example.project_01.commons.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医保政策控制器：处理医保政策相关的HTTP请求
 */
@RestController
@RequestMapping("/medicalPolicy")
@Tag(name = "医保政策模块", description = "医保政策查询相关接口")
public class MedicalPolicyController {

    @Autowired
    private MedicalPolicyService medicalPolicyService;

    /**
     * 根据条件查询医保政策列表（不分页）
     */
    @GetMapping("/list")
    @Operation(summary = "查询医保政策列表（不分页）", description = "根据标题、城市ID等条件查询医保政策列表")
    public List<MedicalPolicyModel> getPolicyList(MedicalPolicyQueryDTO queryDTO) {
        return medicalPolicyService.getPolicyList(queryDTO);
    }

    /**
     * 根据条件分页查询医保政策
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询医保政策", description = "根据条件分页查询医保政策，支持标题模糊查询、城市筛选、时间范围查询")
    public Result getPolicyPage(MedicalPolicyQueryDTO queryDTO) {
        return medicalPolicyService.getPolicyPage(queryDTO);
    }

    /**
     * 根据ID查询医保政策详情
     */
    @GetMapping("/{id}")
    @Operation(summary = "查询医保政策详情", description = "根据ID查询医保政策的详细信息，包含城市名称等扩展字段")
    public MedicalPolicyModel getPolicyById(
            // 显式指定参数名称为"id"，与路径{id}匹配
            @PathVariable("id")
            @Parameter(description = "医保政策ID", example = "1046")
            Long id) {
        return medicalPolicyService.getPolicyById(id);
    }

        /*添加医保政策*/
        @PostMapping("/addMedicalPolicy")
        public Result addMedicalPolicy(@RequestBody MedicalPolicy medicalPolicy){
            System.out.println(medicalPolicy);
            Result result=medicalPolicyService.addMedicalPolicyService(medicalPolicy);
            return result;
        }
        /*根据id删除医保政策*/
        @GetMapping("/delete/{id}")
        public Result deleteById(@PathVariable("id") Long id){
            Result result=medicalPolicyService.deleteByIdService(id);
            return result;
        }

        /*查询所有医保政策数据*/
        @GetMapping("/getAll")
        public Result getAll(){
            Result result=medicalPolicyService.findAllMedicalPolicyService();
            return result;
        }

        /*修改医保政策数据*/

        @PutMapping("/updateMedicalPolicy") // 改为PUT方法，移除冗余路径参数
        public Result updateMedicalPolicy(@RequestBody MedicalPolicy medicalPolicy) {
            Result result = medicalPolicyService.updateMedicalPolicyByIdService(medicalPolicy);
            return result;
        }

}
